package com.wenzhiguo.myheadline.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wenzhiguo.lazyviewpager.LazyFragmentPagerAdapter;
import com.wenzhiguo.lazyviewpager.LazyViewPager;
import com.wenzhiguo.myheadline.R;
import com.wenzhiguo.myheadline.fragment.voide.New_Voide_Fragment;
import com.wenzhiguo.pagerslidingtabstrip.PagerSlidingTabStrip;


public class VoideFragment extends Fragment {


    private View view;
    private PagerSlidingTabStrip spl;
    private LazyViewPager lvp;

    public VoideFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_voide, container, false);
        //找控件
        initView();
        //适配器
        setAdapter();
        return view;
    }

    private void initView() {
        spl = (PagerSlidingTabStrip) view.findViewById(R.id.Voide_spl);
        lvp = (LazyViewPager) view.findViewById(R.id.Voide_lvp);
    }

    private void setAdapter() {
        lvp.setAdapter(new MyAdapter(getActivity().getSupportFragmentManager()));
        spl.setViewPager(lvp);
    }

    class MyAdapter extends LazyFragmentPagerAdapter {
        String[] titles = new String[]{"热点视频", "娱乐视频", "搞笑视频", "精品视频"};
        String[] urls = new String[]{"V9LG4B3A0", "V9LG4CHOR", "V9LG4E6VR", "00850FRB"};
        public MyAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        protected Fragment getItem(ViewGroup container, int position) {
            return New_Voide_Fragment.newInstance(titles[position], urls[position]);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }

        @Override
        public int getCount() {
            return titles.length;
        }
    }
}
